<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>项目基本信息列表</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
<div class="searchArea">
    <form id="searchBar">
        <div class="fieldset1 tabel_col clearFix">
			<div class="fieldBox col_50">
			       <div class="label">金融机构</div>
			       <div class="field " >
			           <input name="fncinsid"  id="fncinsid" type="text" class="ui-textbox"  placeholder="请选择"  ltype="combobox" value="" >
			       </div>
			</div>
			<div class="fieldBox col_50">
			       <div class="label">金融机构类型</div>
			       <div class="field" id="instype">
			           	租赁公司
			       </div>
			</div>
			 <div class="fieldBox col_50">    
			   <div class="label">用户名</div>
			       <div class="field">
			           <input name="insUser" id="insUser" type="text" class="ui-textbox" value="${fncPrj.insUser}" >
			        <span id="seeUser" onclick="seeUser();" class="sq-button sq-button-round">显示</span>
			      </div>
			</div>
			<div class="fieldBox col_50">      
			  <div class="label">真实名称</div>
			      <div class="field">
			          <input name="insUserNm" id="insUserNm" type="text" class="ui-textbox" value="${insUserNm}" >
			       </div>
			                  
			</div>
			<div class="fieldBox col_50">      
			   <div class="label">手机号</div>
			       <div class="field">
			           <input name="phone" id="phone" type="text" class="ui-textbox" value="${insUserNm}" >
			       </div>
			                  
			</div>
			<div class="fieldBox col_50">      
			   <div class="label">是否可查贷前数据</div>
			       <div class="field">
			           <input name="insUserFlag" id="insUserFlag1" type="radio" class="ui-textbox" value="1" <c:if test="${fncPrj.insUserFlag==1}">checked</c:if> >可查看
			        <input name="insUserFlag"  id="insUserFlag2"  type="radio" class="ui-textbox" value="0"  <c:if test="${fncPrj.insUserFlag==0||fncPrj.insUserFlag ==null}">checked</c:if>  >不可查看
			       </div>
			                  
			</div>
			<div class="fieldBox col_50">
				<div class="label">显示承租人年龄</div>
				<div class="field">
					<input name="isDisAge" id="isDisAge1" type="radio" class="ui-textbox" value="1" <c:if test="${fncPrj.isDisAge==1}">checked</c:if> >是
					<input name="isDisAge" id="isDisAge2" type="radio" class="ui-textbox" value="0" <c:if test="${fncPrj.isDisAge==0||fncPrj.isDisAge ==null}">checked</c:if> >否
				</div>
			</div>
			<div class="fieldBox col_50">
				<div class="label">显示逾期数据</div>
				<div class="field">
				    <input name="isDisOverdue" id="isDisOverdue1" type="radio" class="ui-textbox" value="1" <c:if test="${fncPrj.isDisOverdue==1}">checked</c:if> >是
				    <input name="isDisOverdue" id="isDisOverdue2" type="radio" class="ui-textbox" value="0" <c:if test="${fncPrj.isDisOverdue==0||fncPrj.isDisOverdue ==null}">checked</c:if> >否
				</div>
			</div>
            <div class="clearFix" style="text-align:center">
             <span id="searchBtn" onclick="searchBtn();"  class="sq-button sq-button-round">选择再融资项目</span>

			</div>
        </div>
    </form>
</div>
 <div class="sqPanel_body">
<div id="ligergrid1" class="sq-grid"></div> 
</div>
</div>
<div class="clearFix" style="text-align:center">
             <span id="addBtn" onclick="save();" class="sq-button sq-button-round">保存</span>

</div>
<script type="text/javascript">
	var grid = null;
	var queryFlag ="${flag}"; //只查询列表
	 var frilist = ${frilist};
	    var combobox=  $("#fncinsid").ligerComboBox({
	     data:frilist,
         selectBoxWidth: 270,
         selectBoxHeight: 150,
         valueField: "id",
         textField: "fundRasInsNm",
         autocomplete: function (e){
             filter_autoComboboxData(e.key, this);
             e.show();
         },
         onChangeValue: function (value) {
             if (this.findValueByText(value) == "") {//清除输入值
                 liger.get("brCd").setValue("");
             }else{
   				 var instype="";				 
            	 $("#instype").html(combobox.getSelected().insTypeCdNm);
            	 searchBtn();
             }
            	 
         }

	    });
	    var url='';
	    
	   function init() {
		
		
	    $("#ligergrid1").ligerGrid({
	    	url: url,
	    	method : 'get',	 
	    	
	        columns: [
	        	{ display: '项目状态', name: 'fncprjstNM', minWidth: 140 ,enabledSort:true}, 
	            
	            { display: '融资报价', name: 'fncscmNM', minWidth: 140 , enabledSort:true}, 
	            
	            { display: '项目编号', name: 'fncprjid', minWidth: 140 ,
	            	enabledSort:true}, 
	          

	            { display: '项目名称', name: 'fncprjnm', minWidth: 200 , enabledSort:true}, 
	            { display: '融资资产种类', name: 'astNm', minWidth: 200 , enabledSort:true}, 
	            
	        ],
	        usePager: false,
	        pageSize:50,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-2,
	        checkbox:true,
	        rownumbers:true
	    });
	    grid = liger.get("ligergrid1");
	    grid.setHeight(100);
	    $("#searchBar").ligerForm();
	    
	   
	    }
	
    function searchBtn(){
		if($("#fncinsid").val()==''){
			$.ligerDialog.SQalert({content: "请选择金融机构",SQ_type: "warning"});
			return;
		}
		
		url='<%=path%>/rfbuss/fncprjbscinfo/initList.do?';
	
		url+="&fncinsid="+combobox.getSelected().id;
		init();
        
       // for (name in data){
        //	alert(name+":"+data[name]);
        //   grid.setParm(name,data[name]);
       // };
       		
       //grid.reload();
	}
	
	
	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
		}
		return dateStr;
	}
	function addBtn(fncinsid){
		var callback = function(){
			 grid.reload();
		}
		  var TAB=top.mainApp.parentTab;
          var currentTabid=TAB.getSelectedTabItemID();

		var timestamp=new Date().getTime();
		Add_navTab('fnc_prj_bsc_info_add'+timestamp,'添加配置信息','<%=path%>/rfbuss/fncprjbscinfo/toInsUserAddPage.do?flag=1&fncinsid='+fncinsid,callback);
	}
	
	
	function seeUser(){
		if($("#insUser").val()==''){
			return;
		}
		$.ajax({
    		type: 'post',
    		dataType:'json',
    		url: '<%=path%>/archive/arcMgrMain/searchBtn.do?idCardNM='+$("#insUser").val(),
			beforeSend: function(){
				wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
			},success:function(msg){
				wait_dialog.close();
				if(msg.success == 1){
					$("#insUserNm").val(msg.data.refRlNm);
					$("#phone").val(msg.data.mp);
				}else{
					$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
				}
			},error:function (XMLHttpRequest, textStatus, errorThrown) { 
				wait_dialog.close();
				$.ligerDialog.SQalert({content: "网络错误，请稍后重试",SQ_type: "error"});
			} 
		});
	}
	
	function detailBtn(fncinsid){
		
		Add_navTab('tab_project_detail'+id,'配置信息详情','<%=path%>/rfbuss/fncprjbscinfo/toInsUserAddPage.do?flag=0&fncinsid='+fncinsid);
	}

    function save(){
    	if($("#fncinsid").val()==''){
    		$.ligerDialog.SQalert({content: "请选择金融机构",SQ_type: "warning"});
    		return ;
    	}
    	var fncinsid=combobox.getSelected().id;
    	
    	var insUser=$("#insUser").val();
    	if($("#insUser").val()==''){
    		$.ligerDialog.SQalert({content: "请选择用户",SQ_type: "warning"});
    		return ;
    	}
    	var selectedRows = grid.getSelectedRows();
    	if (selectedRows.length < 1) {
            $.ligerDialog.SQalert({content: "请选择项目", SQ_type: "warning"});
            return;
        }
    	var allids="";//所有项目数据
    	var griddata= grid.getData();
    	for(var i=0;i<griddata.length;i++){
    		allids=allids+griddata[i].id+",";
    	}
    	var ids="";
    	for(var i=0;i<selectedRows.length;i++){
    		ids=ids+selectedRows[i].id+",";
    	}    	
    	var insUserFlag=$("input[name='insUserFlag']:checked").val();
    	var isDisAge=$("input[name='isDisAge']:checked").val(); //是否显示承租人年龄（1：是，0：否）
    	var isDisOverdue=$("input[name='isDisOverdue']:checked").val(); //是否显示逾期数据（1：是，0：否）
    	var data={
    			fncinsid:fncinsid,
    			insUser:insUser,
    			insUserFlag:insUserFlag,
    			isDisAge:isDisAge,
    			isDisOverdue:isDisOverdue,
    			allids:allids,
    			ids:ids
    	};
    	console.log(data);
    	$.ajax({
    		type: 'post',
    		dataType:'json',
    		url: '<%=path%>/rfbuss/fncprjbscinfo/saveInsUserList.do',
    		data:data,
			beforeSend: function(){
				wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
			},success:function(msg){
				wait_dialog.close();
				if(msg.success == 1){
					$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
					Remove_navTab();//新增，关闭当前页面

				}else{
					$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
				}
			},error:function (XMLHttpRequest, textStatus, errorThrown) { 
				wait_dialog.close();
				$.ligerDialog.SQalert({content: "网络错误，请稍后重试",SQ_type: "error"});
			} 
		});
    	
	}
	
	function fmoney(s, n)   
	{   
	   n = n > 0 && n <= 20 ? n : 2;   
	   s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";   
	   var l = s.split(".")[0].split("").reverse(),   
	   r = s.split(".")[1];   
	   t = "";   
	   for(i = 0; i < l.length; i ++ )   
	   {   
	      t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");   
	   }   
	   return t.split("").reverse().join("") + "." + r;   
	} 
</script>

</body>
</html>